from collections import deque
from typing import List


class Solution:
    def isSelfCrossing(self, distance: List[int]) -> bool:
        # 添加2次距离为0的移动
        now = deque([0, 0])

        i = 0
        while i < len(distance) and i < 4:
            now.append(distance[i])
            i += 1

        while len(now) == 6:
            # 第1类路径交叉的情况
            if now[5] >= now[3] and now[4] <= now[2]:
                return True

            # 第3类路径交叉的情况
            if now[2] - now[0] <= now[4] <= now[2] and now[5] >= now[3] - now[1] and now[3] > now[1]:
                return True

            now.popleft()
            if i < len(distance):
                now.append(distance[i])
                i += 1

        return False


if __name__ == "__main__":
    print(Solution().isSelfCrossing(distance=[2, 1, 1, 2]))  # True
    print(Solution().isSelfCrossing(distance=[1, 2, 3, 4]))  # False
    print(Solution().isSelfCrossing(distance=[1, 1, 1, 1]))  # True
